﻿using System;
using System.Collections.Generic;
using System.Text;
using SqlSugar;

namespace Dora.Orm.SqlSugarCore.UnitOfWork
{
    public class SugarUnitOfwork : InstallSqlSugar, ISugarUnitOfWork
    {
        private SqlSugarClient _modifyClient;
        private static readonly object objlock = new object();
        public SqlSugarClient ModifyClient
        {
            get
            {
                //if (_modifyClient == null)
                //{
                //    lock (objlock)
                //    {
                //        if (_modifyClient == null)
                //        {
                //            _modifyClient = CreateModifyInstence(false);
                //        }
                //    }
                //}
                //return _modifyClient;
                return CreateModifyInstence(false);
            }
        }

        public SqlSugarClient QueryClient
        {
            get
            {
                return CreateQueryInstence(false);
            }
        }

        public void Dispose()
        {
            if (ModifyClient != null)
            {
                ModifyClient.Close();
                ModifyClient.Dispose();
            }

            if (QueryClient != null)
            {
                QueryClient.Close();
                QueryClient.Dispose();
            }
        }

        [Obsolete("SqlSugar直接使用SqlSugarClient.Ado.CommitTran()实现")]
        public int Commit()
        {
            throw new NotImplementedException();
        }

        [Obsolete("SqlSugar直接使用SqlSugarClient.Ado.CommitTran()实现")]
        public void CommitAndRefreshChanges()
        {
            throw new NotImplementedException();
        }

        [Obsolete("SqlSugar直接使用SqlSugarClient.Ado.RollbackTran()实现")]
        public void RollbackChanges()
        {
            throw new NotImplementedException();
        }
    }
}
